package 代码记录.校招笔试真题.笔试真题_2023.神策数据;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zx
 * @create 2023-03-05 16:00
 * IP7转十进制数
 * 90%
 */
public class Test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            if (isIP(str)) {
                String[] arr = str.split("\\.");
                String res = "";
                for(int i = 0;i < arr.length;i++){
                    int temp = 0;
                    if(!arr[i].equals("")){
                        temp = Integer.parseInt(arr[i]);//////
                    }
                    arr[i] = Integer.toString(temp,2);
                    while (arr[i].length() < 8){
                        arr[i] = "0" + arr[i];
                    }
                    res += arr[i];
                }
                System.out.println(Long.parseLong(res,2));
            } else {
                System.out.println(-1);
            }
        }
    }
    private static boolean isIP(String str){
        //首末段不缩写
        if(str.charAt(0) == '.' || str.charAt(str.length() - 1) == '.'){
            return false;
        }
        for(int i = 0;i < str.length();i++){
            char c = str.charAt(i);
            if(!(c == '.' || (c >= '0' && c <= '9'))){
                return false;//非数字
            }
        }
        String[] arr = str.split("\\.");
        if(arr.length != 7) return false;
        for(int i = 0;i < arr.length;i++){
            if(!arr[i].equals("")) {
                int a = Integer.parseInt(arr[i]);
                if(a < 0 || a > 255){
                    return false;
                }
            }
        }
        return true;
    }
}
